/*
 * Copyright (c) 2020 hebeiyiliuba.com
 * All rights reserved.
 *
 */
package org.jeecg.modules.wlhy.report.impl;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.ecs.model.v20140526.DescribePriceResponse;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.dy.wlhy.client.Utils;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.asm.Advice;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.enums.ReportPlatformEnum;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.third.jg.report.freight.information.constant.enums.PaymentMeansCodeEnum;
import org.jeecg.modules.third.jg.report.freight.information.constant.enums.ReportDocTypeEnum;
import org.jeecg.modules.third.jg.report.freight.information.dto.AppInfoDTO;
import org.jeecg.modules.third.jg.report.freight.information.dto.DriverDTO;
import org.jeecg.modules.third.jg.report.freight.information.dto.VehicleDTO;
import org.jeecg.modules.third.jg.report.freight.information.dto.enterprise.AppsDTO;
import org.jeecg.modules.third.jg.report.freight.information.dto.enterprise.EnterpriseDTO;
import org.jeecg.modules.third.jg.report.freight.information.dto.financial.FinancialDTO;
import org.jeecg.modules.third.jg.report.freight.information.dto.financial.FinanciallistDTO;
import org.jeecg.modules.third.jg.report.freight.information.dto.financial.ShippingNoteListDTO;
import org.jeecg.modules.third.jg.report.freight.information.dto.shippingnote.*;
import org.jeecg.modules.third.jg.report.freight.information.model.ExchangeModel;
import org.jeecg.modules.third.jg.report.freight.information.model.LiaoningReqModel;
import org.jeecg.modules.third.jg.report.freight.information.model.LiaoningRspModel;
import org.jeecg.modules.third.jg.report.freight.information.service.LiaoNingUtils;
import org.jeecg.modules.wlhy.bill.entity.HyDriverBill;
import org.jeecg.modules.wlhy.bill.entity.HyShippingNoteBill;
import org.jeecg.modules.wlhy.bill.service.IHyDriverBillService;
import org.jeecg.modules.wlhy.bill.service.IHyShippingNoteBillService;
import org.jeecg.modules.wlhy.company.entity.HyCompany;
import org.jeecg.modules.wlhy.company.entity.HyCompanyConfig;
import org.jeecg.modules.wlhy.company.service.IHyCompanyService;
import org.jeecg.modules.wlhy.customer.entity.HyCustomer;
import org.jeecg.modules.wlhy.customer.service.IHyCustomerService;
import org.jeecg.modules.wlhy.enterprise.entity.HyEnterprise;
import org.jeecg.modules.wlhy.enterprise.service.IHyEnterpriseService;
import org.jeecg.modules.wlhy.hyarea.entity.HyArea;
import org.jeecg.modules.wlhy.hyarea.service.IHyAreaService;
import org.jeecg.modules.wlhy.hydriver.entity.HyDriver;
import org.jeecg.modules.wlhy.hydriver.entity.HyDriverReport;
import org.jeecg.modules.wlhy.hydriver.service.IHyDriverReportService;
import org.jeecg.modules.wlhy.hydriver.service.IHyDriverService;
import org.jeecg.modules.wlhy.hydriverbank.entity.HyDriverBank;
import org.jeecg.modules.wlhy.hydriverbank.service.IHyDriverBankService;
import org.jeecg.modules.wlhy.hyvehicle.entity.HyVehicle;
import org.jeecg.modules.wlhy.hyvehicle.entity.HyVehicleReport;
import org.jeecg.modules.wlhy.hyvehicle.entity.HyVehicleType;
import org.jeecg.modules.wlhy.hyvehicle.service.IHyVehicleReportService;
import org.jeecg.modules.wlhy.hyvehicle.service.IHyVehicleService;
import org.jeecg.modules.wlhy.order.entity.HyOrder;
import org.jeecg.modules.wlhy.order.service.IHyOrderService;
import org.jeecg.modules.wlhy.report.IReportService;
import org.jeecg.modules.wlhy.shipping.constant.ShippingPayStatus;
import org.jeecg.modules.wlhy.shipping.entity.HyShippingNote;
import org.jeecg.modules.wlhy.shipping.service.IHyShippingNoteService;
import org.jeecg.modules.wlhy.utils.HyCfgUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;


/**
 * @BelongsPackage: org.jeecg.modules.wlhy.report.impl
 * @Author: duanlikao
 * @CreateTime: 2023-03-25 09:39
 * @Description:
 * @Version: 1.0
 */
@Service
@Slf4j
public class LiaoNingReportService implements IReportService {
    @Resource
    private BaseReportService baseReportService;

    @Resource
    private IHyDriverService driverService;

    @Resource
    private IHyVehicleService vehicleService;

    @Resource
    private IHyEnterpriseService enterpriseService ;

    @Resource
    private IHyDriverReportService hyDriverReportService;

    @Resource
    private IHyVehicleReportService vehicleReportService;

    @Autowired
    private IHyCustomerService customerService;

    @Autowired
    private IHyOrderService orderService;

    @Autowired
    private IHyCompanyService companyService;

    @Autowired
    private IHyShippingNoteService hyShippingNoteService;

    @Autowired
    private IHyShippingNoteBillService hyShippingNoteBillService;

    @Autowired
    private IHyAreaService hyAreaService;

    @Autowired
    private IHyDriverBankService hydriverBankService;

    @Autowired
    private IHyDriverBillService hyDriverBillService;

    //@Value(value="${ln-report-platform.username:}")
    private String username;

    //@Value(value="${ln-report-platform.password:}")
    private String password;

    //@Value(value="${ln-report-platform.publicKey:}")
    private String publicKey;

    //@Value(value="${ln-report-platform.appId:}")
    private String appId;

    //@Value(value="${ln-report-platform.appSecurity:}")
    private String appSecurity;

    //@Value(value="${ln-report-platform.appSenderCode:}")
    private String appSenderCode;

    //@Value(value="${ln-report-platform.appDebugSystem:}")
    private String appDebugSystem;

    @Override
    public AppInfoDTO getAppInfo() {
        return AppInfoDTO.builder()
                .appId(this.appId)
                .appSecurity(this.appSecurity)
                .enterpriseSenderCode(this.appSenderCode)
                .debugSystem(this.appDebugSystem)
                .build();
    }

    @Override
    public ReportPlatformEnum getReportType() {
        return ReportPlatformEnum.REPORT_PLATFORM_LN;
    }

    @Override
    public void checkReport() {
        //辽宁监管平台
        if(!HyCfgUtil.isUsed2("liaoning_report")){
            throw new JeecgBootException("辽宁上报服务暂未开启,请联系管理员");
        }
    }

    @Override
    public Result setReportInfo(HyCompanyConfig hyCompanyConfig) {

        if (StrUtil.isEmpty(hyCompanyConfig.getReportUsername()) || StrUtil.isEmpty(hyCompanyConfig.getReportPassword()) || StrUtil.isEmpty(hyCompanyConfig.getReportPublickey())) {
            return Result.error("辽宁监管平台参数配置错误!");
        }

        //联调状态的App需要设置debugSystem
        if ("0".equals(hyCompanyConfig.getReportApprelease())) {
            this.appDebugSystem = "debugSystem";
        }

        this.username = hyCompanyConfig.getReportUsername();
        this.password = hyCompanyConfig.getReportPassword();
        this.publicKey = hyCompanyConfig.getReportPublickey();
        this.appId = hyCompanyConfig.getReportAppid();
        this.appSecurity = hyCompanyConfig.getReportAppkey();
        this.appSenderCode = hyCompanyConfig.getReportAppsender();

        return Result.ok("设置成功");
    }


    @Override
    @Deprecated
    public boolean report(HyShippingNote hyShippingNote) {
        return false;
    }

    @Override
    public Result reportShippingNote(HyShippingNote hyShippingNote) {
        Result result = this.checkDriverAndVehicle(hyShippingNote);
        if (!result.getCode().equals(CommonConstant.SC_OK_200)) {
            return result;
        }
        return this.uploadShippingNote(hyShippingNote);
    }

    @Override
    public Result reportCapitalFlow(HyShippingNote hyShippingNote) {
        Result result = this.checkDriverAndVehicle(hyShippingNote);
        if (!result.getCode().equals(CommonConstant.SC_OK_200)) {
            return result;
        }
        return this.uploadCapitalFlow(hyShippingNote.getId());
    }

    //上报运单和资金流水前，先确认司机、车辆的上传状态
    private Result checkDriverAndVehicle(HyShippingNote hyShippingNote) {

        String driverId = hyShippingNote.getDriverId();
        String vehicleId = hyShippingNote.getVehicleId();
        if (StrUtil.isEmpty(driverId)) {
            return Result.error("当前运单司机信息不存在");
        }

        if (StrUtil.isEmpty(vehicleId)) {
            return Result.error("当前运单车辆信息不存在");
        }

        //自动上报司机和车辆配置
        String autoUpload = HyCfgUtil.getCfgItem2("liaoning_report","auto_upload");

        boolean bDriverUploadStatus = this.hyDriverReportService.checkUploadStatus(driverId, hyShippingNote.getCompanyId(),
                ReportPlatformEnum.REPORT_PLATFORM_LN.getCode());
        if (!bDriverUploadStatus) {
            if (StrUtil.isEmpty(autoUpload) || !autoUpload.equals("1")) {
                return Result.error("请先同步司机数据");
            }
            log.warn("司机未上报辽宁监管，开始同步司机数据, {}", driverId);
            Result dResult = this.reportDriver(driverId, hyShippingNote.getCompanyId());
            if (!dResult.getCode().equals(CommonConstant.SC_OK_200)) {
                return dResult;
            }
        }

        boolean bVehicleUploadStatus = this.vehicleReportService.checkUploadStatus(vehicleId, hyShippingNote.getCompanyId(),
                ReportPlatformEnum.REPORT_PLATFORM_LN.getCode());
        if (!bVehicleUploadStatus) {
            if (StrUtil.isEmpty(autoUpload) || !autoUpload.equals("1")) {
                return Result.error("请先同步车辆数据");
            }
            log.warn("车辆未上报辽宁监管，开始同步车辆数据, {}", vehicleId);
            Result vResult = this.reportVehicle(vehicleId, hyShippingNote.getCompanyId());
            if (!vResult.getCode().equals(CommonConstant.SC_OK_200)) {
                return vResult;
            }
        }

        return Result.OK();
    }



    /**
     * 按运单上传司机和车辆信息
     * @param driverId
     * @param vehicleId
     */

    private boolean upDriverAndVehicle(String driverId,String vehicleId) {
        return false;
    }


    public Result uploadCapitalFlow(String shippingId){

        if(!HyCfgUtil.isUsed("liaoning_report")){
            throw new JeecgBootException("辽宁省平台上报服务暂未开启,请联系管理。");
        }

        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("shipping_id", shippingId);
        List<HyShippingNoteBill> shippingNoteBills = hyShippingNoteBillService.list(queryWrapper);

        if (CollectionUtils.isEmpty(shippingNoteBills)) {
            throw new JeecgBootException("未找到对应数据");
        }

        HyShippingNote hyShippingNote = hyShippingNoteService.getById(shippingId);
        if (!hyShippingNote.getUploadStatus().equals("1")) {
            return Result.error("请先上报运单数据");
        }
        if (!hyShippingNote.getShippingPayStatus().equals(ShippingPayStatus.支付完成.getValue())) {
            return Result.error("该运单未支付完成");
        }

        String xmlString = buildFinancialXMLData(shippingNoteBills, hyShippingNote, this.username, this.publicKey);
        try {
            log.info("辽宁上报请求 -> {}", xmlString);
            String reportResult = LiaoNingUtils.send(ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_ZJ.getCode1() , this.username, this.password, xmlString);
            log.info("辽宁上报回执 <- {}", reportResult);
            if(StringUtils.isNotEmpty(reportResult)){
                LiaoningRspModel rspModel = buildResponseData(reportResult, "RtnValZjlssb");
                boolean bResultFlag = StringUtils.isNotBlank(rspModel.getCode()) && rspModel.getCode().equals("000000") ? true : false;
                String message = rspModel.getMessage();
                //特殊处理，提示重复也算成功
                if (StrUtil.isNotEmpty(message) && message.contains("重复")) {
                    bResultFlag = true;
                }

                //截取错误日志
                if (!bResultFlag) {
                    message = message.substring(0, message.indexOf("#"));
                }

                for (HyShippingNoteBill shippingNoteBillDb :  shippingNoteBills){
                    shippingNoteBillDb.setUploadStatus(bResultFlag ?  "1" : "2");
                    shippingNoteBillDb.setReportFailureReason(bResultFlag ?  "" : message);
                    shippingNoteBillDb.setUploadDate(new Date());
                    shippingNoteBillDb.setReportPlatformType(ReportPlatformEnum.REPORT_PLATFORM_LN.getCode());
                }
                log.info("辽宁监管资金流水上报, {}", reportResult);
                hyShippingNoteBillService.updateBatchById(shippingNoteBills);
                return bResultFlag ? Result.OK("上报成功") : Result.error(message);
            }else{
                throw new JeecgBootException("未知异常");
            }
        }catch (Exception e){
            log.error(e.getMessage());
            e.printStackTrace();
            for(HyShippingNoteBill shippingNoteBillDb :  shippingNoteBills){
                shippingNoteBillDb.setUploadStatus("2");
                shippingNoteBillDb.setReportFailureReason(e.getMessage());
                shippingNoteBillDb.setUploadDate(new Date());
                shippingNoteBillDb.setReportPlatformType(ReportPlatformEnum.REPORT_PLATFORM_LN.getCode());
            }
            hyShippingNoteBillService.updateBatchById(shippingNoteBills);
        }

        return Result.error("资金流水单上报错误");
    }


    /**
     * 平台上报电子运单
     *
     * @param hyShippingNote
     * @return
     */
    public Result uploadShippingNote(HyShippingNote hyShippingNote) {
        if (!HyCfgUtil.isUsed("liaoning_report")) {
            throw new JeecgBootException("辽宁省平台上报服务暂未开启,请联系管理。");
        }

        HyShippingNote ShippingNoteDb = hyShippingNoteService.getById(hyShippingNote.getId());
        if (ShippingNoteDb == null) {
            throw new JeecgBootException("未找到对应数据");
        }
        if ("1".equals(ShippingNoteDb.getUploadStatus())) {
            return Result.OK("上报成功");
        }


        //if (!"2".equals(hyShippingNote.getUploadStatus())) {
        //    baseReportService.checkShippingNoteRoute(hyShippingNote);
        //}

        //appPasswd : "04f072c54a44a92842d0298a46fedc38"
        String xmlString = buildShippingNoteXMLData(hyShippingNote, this.username, this.publicKey);

        try {
            log.info("辽宁上报请求 -> {}", xmlString);
            String reportResult = LiaoNingUtils.send(ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_YD.getCode1(), this.username, this.password, xmlString);
            log.info("辽宁上报回执 <- {}", reportResult);
            if (StringUtils.isNotEmpty(reportResult)) {
                LiaoningRspModel rspModel = buildResponseData(reportResult, "RtnValDzydsb");
                boolean bResultFlag = StringUtils.isNotBlank(rspModel.getCode()) && rspModel.getCode().equals("000000") ? true : false;
                String message = rspModel.getMessage();
                //特殊处理，提示重复也算成功
                if (StrUtil.isNotEmpty(message) && message.contains("重复")) {
                    bResultFlag = true;
                }

                //截取错误日志
                if (!bResultFlag) {
                    message = message.substring(0, message.indexOf("#"));
                }

                ShippingNoteDb.setUploadStatus(bResultFlag ? "1" : "2");
                ShippingNoteDb.setReportFailureReason(bResultFlag ? "" : message);
                ShippingNoteDb.setUploadDate(new Date());
                ShippingNoteDb.setReportPlatformType(ReportPlatformEnum.REPORT_PLATFORM_LN.getCode());
                hyShippingNoteService.updateById(ShippingNoteDb);
                log.error("记录辽宁监管上传运单回执信息，{}", reportResult);
                return bResultFlag ? Result.OK("上报成功") : Result.error(message);
            } else {
                throw new JeecgBootException("未知异常");
            }
        } catch (Exception e) {
            log.error(e.getMessage());
            e.printStackTrace();
            ShippingNoteDb.setUploadStatus("2");
            ShippingNoteDb.setReportFailureReason(e.getMessage());
            ShippingNoteDb.setUploadDate(new Date());
            ShippingNoteDb.setReportPlatformType(ReportPlatformEnum.REPORT_PLATFORM_LN.getCode());
            hyShippingNoteService.updateById(ShippingNoteDb);
        }

        return Result.error("运单上报数据错误");
    }

    /**
     * 平台司机上报
     *
     * @param driverId
     * @return
     */
    @Override
    public Result<?> reportDriver(String driverId, String companyId) {

        if (!HyCfgUtil.isUsed("liaoning_report")) {
            throw new JeecgBootException("辽宁省平台上报服务暂未开启,请联系管理。");
        }

        HyDriver hyDriverDb = driverService.getById(driverId);
        if (hyDriverDb == null) {
            throw new JeecgBootException("未找到对应数据");
        }

        HyDriverReport hyDriverReport = new HyDriverReport();
        //人员从业资格证验证
        if (!driverService.checkQualificationV2(hyDriverDb)) {
            throw new JeecgBootException("人员从业资格证验证号不正确或者已过期，请修改后重新上传！");
        }

        String xmlString = buildDriverXMLData(hyDriverDb, this.username, this.publicKey);
        log.info("辽宁上报司机报文 --->,{}, {}, {}, {}", this.username, this.password, this.publicKey, xmlString);

        try {
            String reportResult = LiaoNingUtils.send(
                    ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_JSY.getCode1(), this.username, this.password, xmlString);
            log.warn("辽宁司机上报回执 <---, {}", reportResult);

            if (StringUtils.isNotEmpty(reportResult)) {

                LiaoningRspModel rspModel = buildResponseData(reportResult, "RtnValJsysb");
                boolean bResultFlag = StringUtils.isNotBlank(rspModel.getCode()) && rspModel.getCode().equals("000000") ? true : false;
                String message = rspModel.getMessage();
                //特殊处理，提示重复驾驶员上传也算成功
                if (StrUtil.isNotEmpty(message) && message.contains("重复驾驶员上传")) {
                    bResultFlag = true;
                }
                //截取错误日志
                if (!bResultFlag) {
                    message = message.substring(0, message.indexOf("#"));
                }

                hyDriverReport.setCompanyId(companyId);
                hyDriverReport.setDriverId(driverId);
                hyDriverReport.setReportPlatformType(ReportPlatformEnum.REPORT_PLATFORM_LN.getCode());
                hyDriverReport.setDriverUploadStatus(bResultFlag ? "1" : "2");
                hyDriverReport.setUploadDate(new Date());
                hyDriverReport.setDriverReportFailureReason(message);

                this.driverService.updateJgUploadStatusById(driverId, hyDriverReport.getDriverUploadStatus());
                log.info("辽宁监管更新司机上报回执信息, {}, {}", bResultFlag, message);
                this.hyDriverReportService.saveDriverReport(hyDriverReport);

                return bResultFlag ? Result.OK("上报成功") : Result.error(message);
            } else {
                throw new JeecgBootException("未知异常");
            }
        } catch (Exception e) {
            hyDriverReport.setDriverId(driverId);
            hyDriverReport.setCompanyId(companyId);
            hyDriverReport.setReportPlatformType(ReportPlatformEnum.REPORT_PLATFORM_LN.getCode());
            hyDriverReport.setDriverUploadStatus("2");
            hyDriverReport.setUploadDate(new Date());
            hyDriverReport.setDriverReportFailureReason(e.getMessage());
            hyDriverReportService.saveDriverReport(hyDriverReport);
        }

        return Result.error("上报错误，请联系管理员");
    }


    @Override
    public Result<?> reportVehicle(String vehicleId, String companyId) {

        if(!HyCfgUtil.isUsed("liaoning_report")){
            throw new JeecgBootException("辽宁省平台上报服务暂未开启,请联系管理。");
        }

        HyVehicle hyVehiclDb = vehicleService.getById(vehicleId);
        if(hyVehiclDb == null) {
            throw new JeecgBootException("未找到对应数据");
        }

        HyVehicleReport hyVehicleReport = new HyVehicleReport();

        if (StringUtils.isEmpty(hyVehiclDb.getRoadTransportNumber())) {
            throw new JeecgBootException("车辆道路运输证不能为空！");
        }

        if (!vehicleService.checkRTCNoV2(hyVehiclDb)) {
            throw new JeecgBootException("车辆道路运输证号不正确或者已过期，请修改后重新上传！");
        }

        HyVehicleType hyVehicleType = vehicleService.getHyVehicleType(hyVehiclDb.getVehicleType());
        if (hyVehicleType == null) {
            throw new JeecgBootException("车辆类型不存在,修改后请重新上报！");
        }
        hyVehiclDb.setVehicleType(hyVehicleType.getValue());

        String xmlString = buildVehicleXMLData(hyVehiclDb, this.username, this.publicKey);

        try {
            log.info("辽宁上报车辆报文 --->,{}, {}, {}, {}", this.username, this.password, this.publicKey, xmlString);
            String reportResult = LiaoNingUtils.send(
                    ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_CL.getCode1(), this.username, this.password, xmlString);
            log.warn("辽宁车辆上报回执 <---, {}", reportResult);
            if(StringUtils.isNotEmpty(reportResult)){
                LiaoningRspModel rspModel = buildResponseData(reportResult, "RtnValClxxsb");
                boolean bResultFlag = StringUtils.isNotBlank(rspModel.getCode()) && rspModel.getCode().equals("000000") ? true : false;
                String message = rspModel.getMessage();
                //特殊处理，提示重复驾驶员上传也算成功
                if (StrUtil.isNotEmpty(message) && message.contains("重复")) {
                    bResultFlag = true;
                }

                //截取错误日志
                if (!bResultFlag) {
                    message = message.substring(0, message.indexOf("#"));
                }

                hyVehicleReport.setCompanyId(companyId);
                hyVehicleReport.setVehicleId(vehicleId);
                hyVehicleReport.setReportPlatformType(ReportPlatformEnum.REPORT_PLATFORM_LN.getCode());
                hyVehicleReport.setVehicleUploadStatus(bResultFlag ? "1" : "2");
                hyVehicleReport.setUploadDate(new Date());
                hyVehicleReport.setVehicleReportFailureReason(message);

                this.vehicleService.updateJgUploadStatusById(vehicleId, hyVehicleReport.getVehicleUploadStatus());
                log.info("辽宁监管更新车辆上报回执信息, {}, {}", bResultFlag, message);
                this.vehicleReportService.saveVehicleReport(hyVehicleReport);

                return bResultFlag ? Result.OK("上报成功") : Result.error(message);
            } else {
                throw new JeecgBootException("未知异常");
            }
        }catch (Exception e){
            hyVehicleReport.setVehicleId(vehicleId);
            hyVehicleReport.setCompanyId(companyId);
            hyVehicleReport.setReportPlatformType(ReportPlatformEnum.REPORT_PLATFORM_LN.getCode());
            hyVehicleReport.setVehicleUploadStatus( "2");
            hyVehicleReport.setUploadDate( new Date() );
            hyVehicleReport.setVehicleReportFailureReason(e.getMessage());
            vehicleReportService.saveVehicleReport(hyVehicleReport);
        }

        return Result.error("上报错误，请联系管理员");
    }


    public Result<?> reportEnterprise(String actionType) {

        this.username = "40612";
        this.password = "zmgs-4258";
        this.publicKey = "adc538c0ba18b6605c51e2dd33206f3a";
        String xmlString = buildEnterpriseXMLData(actionType, this.username, this.publicKey);
        log.info("辽宁上报企业信息报文 --->,{}, {}, {}, {}", this.username, this.password, this.publicKey, xmlString);

        try {
            String reportResult = LiaoNingUtils.send(
                    ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_QY.getCode1(), this.username, this.password, xmlString);
            log.warn("辽宁上报企业信息回执 <---, {}", reportResult);

            //String reportResult = "";
            if (StringUtils.isNotEmpty(reportResult)) {

//                LiaoningRspModel rspModel = buildResponseData(reportResult, "RtnValJsysb");
//                boolean bResultFlag = StringUtils.isNotBlank(rspModel.getCode()) && rspModel.getCode().equals("000000") ? true : false;
//                String message = rspModel.getMessage();
//                //特殊处理，提示重复驾驶员上传也算成功
//                if (StrUtil.isNotEmpty(message) && message.contains("重复驾驶员上传")) {
//                    bResultFlag = true;
//                }
//                //截取错误日志
//                if (!bResultFlag) {
//                    message = message.substring(0, message.indexOf("#"));
//                }
//
//                hyDriverReport.setCompanyId(companyId);
//                hyDriverReport.setDriverId(driverId);
//                hyDriverReport.setReportPlatformType(ReportPlatformEnum.REPORT_PLATFORM_LN.getCode());
//                hyDriverReport.setDriverUploadStatus(bResultFlag ? "1" : "2");
//                hyDriverReport.setUploadDate(new Date());
//                hyDriverReport.setDriverReportFailureReason(message);
//
//                this.driverService.updateJgUploadStatusById(driverId, hyDriverReport.getDriverUploadStatus());
//                log.info("辽宁监管更新司机上报回执信息, {}, {}", bResultFlag, message);
//                this.hyDriverReportService.saveDriverReport(hyDriverReport);

                return Result.OK("上报成功");
            }
        } catch (Exception e) {

        }

        return Result.error("上报错误，请联系管理员");
    }

    //生成司机数据报文
    private String buildDriverXMLData(HyDriver hyDriver, String appId, String passwd) {

        LiaoningReqModel exchangeModel = new LiaoningReqModel();
        LiaoningReqModel.Root root = new LiaoningReqModel.Root();
        exchangeModel.setRoot(root);
        LiaoningReqModel.Header header = buildHeaderData(appId,
                ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_JSY.getMsg(),
                ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_JSY.getCode(),
                passwd);
        root.setHeader(header);

        //实体
        DriverDTO driverDTO = new DriverDTO();
        driverDTO.setDriverName(hyDriver.getDriverName());
        driverDTO.setAppkey(appId);
        driverDTO.setDrivingLicense(hyDriver.getDrivingLicense());
        driverDTO.setQualificationCertificate(hyDriver.getDrivingLicense());
        driverDTO.setIssuingOrganizations(hyDriver.getIssuingOrganizations());
        driverDTO.setValidPeriodFrom(DateUtils.dateToStringNoBar(hyDriver.getValidPeriodFrom()));
        driverDTO.setValidPeriodTo(DateUtils.dateToStringNoBar(hyDriver.getValidPeriodTo()));
        driverDTO.setTelephone(hyDriver.getTelephone());
        driverDTO.setVehicleClass(hyDriver.getVehicleClass());

        root.setDriverDTO(driverDTO);

        XStream xstream = new XStream(new DomDriver( "utf-8"));
        xstream.aliasSystemAttribute(null, "class");
        xstream.processAnnotations(LiaoningReqModel.class);

        return xstream.toXML(exchangeModel);
    }

    //生成车辆XML上报报文
    private String buildVehicleXMLData(HyVehicle hyVehicle, String appId, String passwd) {
        LiaoningReqModel exchangeModel = new LiaoningReqModel();
        LiaoningReqModel.Root root = new LiaoningReqModel.Root();
        exchangeModel.setRoot(root);
        LiaoningReqModel.Header header = buildHeaderData(appId,
                ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_CL.getMsg(),
                ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_CL.getCode(),
                passwd);
        root.setHeader(header);

        //实体
        VehicleDTO vehicleDTO = new VehicleDTO();
        vehicleDTO.setVehicleNumber(hyVehicle.getVehicleNumber());
        vehicleDTO.setAppkey(appId);
        vehicleDTO.setVehiclePlateColorCode(hyVehicle.getVehiclePlateColorCode());
        vehicleDTO.setVehicleType(hyVehicle.getVehicleType());
        vehicleDTO.setOwner(hyVehicle.getOwner());
        vehicleDTO.setUseCharacter(hyVehicle.getUseCharacter());
        vehicleDTO.setVin(hyVehicle.getVin());
        vehicleDTO.setIssuingOrganizations(hyVehicle.getIssuingOrganizations());
        vehicleDTO.setRegisterDate(DateUtils.dateToStringNoBar(hyVehicle.getRegisterDate()));
        vehicleDTO.setIssueDate(DateUtils.dateToStringNoBar(hyVehicle.getIssueDate()));
        vehicleDTO.setVehicleEnergyType(hyVehicle.getVehicleEnergyType());
        vehicleDTO.setVehicleTonnage(String.valueOf(hyVehicle.getVehicleTonnage()));
        //总质量保留2位小数
        vehicleDTO.setGrossMass(String.format("%.2f", hyVehicle.getGrossMass()));
        vehicleDTO.setRoadTransportCertificateNumber(hyVehicle.getRoadTransportNumber());
        root.setVehicleDTO(vehicleDTO);

        XStream xstream = new XStream(new DomDriver( "utf-8"));
        xstream.aliasSystemAttribute(null, "class");
        xstream.processAnnotations(LiaoningReqModel.class);

        return xstream.toXML(exchangeModel);
    }

    //生成车辆XML上报报文
    private String buildShippingNoteXMLData(HyShippingNote hyShippingNote, String appId, String passwd) {
        if (hyShippingNote == null) {
            throw new JeecgBootException("该运单上报信息不能为空");
        }

        HyCustomer hyCustomer = customerService.getById(hyShippingNote.getCustomerId());
        if (hyCustomer == null) {
            throw new JeecgBootException("该运单货主信息不能为空");
        }

        HyOrder hyOrder = orderService.getById(hyShippingNote.getOrderId());
        if (hyOrder == null) {
            throw new JeecgBootException("该运单货源信息不能为空");
        }

        HyDriver hyDriver = driverService.getById(hyShippingNote.getDriverId());

        if (hyDriver == null) {
            throw new JeecgBootException("该运单司机信息不能为空");
        }
        HyVehicle hyVehicle = vehicleService.getById(hyShippingNote.getVehicleId());
        if (hyVehicle == null) {
            throw new JeecgBootException("该运单车辆信息不能为空");
        }

        if (hyVehicle.getOwner().contains("公司") && StrUtil.isEmpty(hyVehicle.getOwnerCode())) {
            throw new JeecgBootException("车辆所有人社会信用代码错误");
        }

        HyCompany company = companyService.getById(hyShippingNote.getCompanyId());
        if (company == null) {
            throw new JeecgBootException("该运单公司信息不能为空");
        }

        //头部信息
        LiaoningReqModel exchangeModel = new LiaoningReqModel();
        LiaoningReqModel.Root root = new LiaoningReqModel.Root();
        exchangeModel.setRoot(root);
        LiaoningReqModel.Header header = buildHeaderData(appId,
                ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_YD.getMsg(),
                ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_YD.getCode(),
                passwd);
        root.setHeader(header);

        //实体
        ShippingNoteDTO shippingNoteDTO = new ShippingNoteDTO();
        shippingNoteDTO.setOriginalDocumentNumber(hyOrder.getOrderNum());
        String shippingNoteNumber = hyShippingNote.getShippingNoteNumber().replaceAll("-", "");
        if (shippingNoteNumber.length() > 20) {
            shippingNoteNumber = shippingNoteNumber.substring(0, 20);
        }
        shippingNoteDTO.setShippingNoteNumber(shippingNoteNumber);
        shippingNoteDTO.setSerialNumber("0000");
        shippingNoteDTO.setVehicleAmount(1);
        shippingNoteDTO.setTransportTypeCode(1);
        //运单上传时间
        shippingNoteDTO.setSendToProDateTime(header.getMessageSendingDateTime());
        //网络货运经营者名称
        shippingNoteDTO.setCarrier(company.getCompanyName());
        //统一社会信用代码
        shippingNoteDTO.setUnifiedSocialCreditIdentifier(company.getCreditCode());
        //车辆 道路运输经营许可 网络货运经营者的道路 运输经营许可证编号。
        shippingNoteDTO.setPermitNumber(company.getPermitNumber());
        //运单生成时间
        shippingNoteDTO.setConsignmentDateTime(DateUtils.dateToStringDateTime(hyShippingNote.getCreateTime()));
        shippingNoteDTO.setBusinessTypeCode(hyShippingNote.getBusinessTypeCode());
        //发货日期时间
        shippingNoteDTO.setDespatchActualDateTime(DateUtils.dateToStringDateTime(hyShippingNote.getStatusDtLoading()));
        //收货日期时间
        shippingNoteDTO.setGoodsReceiptDateTime(DateUtils.dateToStringDateTime(hyShippingNote.getStatusDtUnloading()));
        //运费总金额
        BigDecimal costPay = hyShippingNote.getGoodsWeightLoading().multiply(hyShippingNote.getShippingUnitPrice());
        BigDecimal costPayShipping = hyShippingNote.getDriverFee() != null ?  hyShippingNote.getDriverFee() : costPay ;
        shippingNoteDTO.setTotalMonetaryAmount(costPayShipping.setScale(3, BigDecimal.ROUND_DOWN).toString());

        //托运人信息
        ConsignorInfo consignorInfo = new ConsignorInfo();
        consignorInfo.setConsignor(hyCustomer.getCustomerName());
        consignorInfo.setConsignorId(
                StringUtils.isNotBlank(hyCustomer.getCreditCode()) ? hyCustomer.getCreditCode() : hyCustomer.getIdcard()
        );
        consignorInfo.setPlaceOfLoading(hyShippingNote.getSendAddress());
        consignorInfo.setCountrySubdivisionCode(hyShippingNote.getSendAreaCode());
        shippingNoteDTO.setConsignorInfo(consignorInfo);
        //baseReportService.getConsignorInfo(hyCustomer, hyShippingNote, shippingNoteDTO);
        //收货方信息
        //baseReportService.getConsigneeInfo(hyShippingNote, shippingNoteDTO);
        ConsigneeInfo consigneeInfo = new ConsigneeInfo();
        consigneeInfo.setConsignee(hyShippingNote.getReceiveContactName());
        consigneeInfo.setGoodsReceiptPlace(hyShippingNote.getReceiveAddress());
        consigneeInfo.setCountrySubdivisionCode(hyShippingNote.getReceiveAreaCode());
        shippingNoteDTO.setConsigneeInfo(consigneeInfo);

        //价格
        shippingNoteDTO.setPriceInfo(new PriceInfo(shippingNoteDTO.getTotalMonetaryAmount(), "人民币"));
        //辽宁上报车辆信息
        LiaoningVehicleInfo liaoningVehicleInfo = new LiaoningVehicleInfo();
        liaoningVehicleInfo.setVehiclePlateColorCode(hyVehicle.getVehiclePlateColorCode());
        liaoningVehicleInfo.setVehicleNumber(hyVehicle.getVehicleNumber());
        liaoningVehicleInfo.setDriver(DriverDTO.builder()
                .driverName(hyDriver.getDriverName())
                .drivingLicense(hyDriver.getDrivingLicense())
                .build());
        liaoningVehicleInfo.setGoodsInfo(GoodsInfo.builder()
                .descriptionOfGoods(hyShippingNote.getDescriptionOfGoods())
                .cargoTypeClassificationCode(hyShippingNote.getCargoTypeClassificationCode())
                //吨换算千克
                .goodsItemGrossWeight("1".equals(hyOrder.getGoodsUnit()) ? hyShippingNote.getGoodsWeightLoading().multiply(new BigDecimal(1000)).setScale(3, BigDecimal.ROUND_DOWN).toString() : "0.000")
                .cube("3".equals(hyOrder.getGoodsUnit()) ? hyShippingNote.getGoodsWeightLoading().setScale(4, BigDecimal.ROUND_DOWN).toString() : "1.0000")
                .totalNumberOfPackages(1)
                .build());
        shippingNoteDTO.setLiaoningVehicleInfo(liaoningVehicleInfo);

        //实际承运人信息
        //辽宁上报特殊需求，如果是运输公司，实际承运人需要上传的是公司名称、社会信用代码以及车辆的道路运输证号
        ActualCarrierInfo actualCarrierInfo = new ActualCarrierInfo();
        if (!hyVehicle.getOwner().contains("公司")) {
            actualCarrierInfo.setActualCarrierName(hyDriver.getDriverName());
            actualCarrierInfo.setActualCarrierBusinessLicense(
                    StringUtils.isNotBlank(hyVehicle.getBusinessLicense()) ? hyVehicle.getBusinessLicense() :
                            hyVehicle.getRoadTransportNumber().substring(0 , 6) +"000000"
            );
            actualCarrierInfo.setActualCarrierId(hyDriver.getIdcard());
        } else {
            actualCarrierInfo.setActualCarrierName(hyVehicle.getOwner());
            actualCarrierInfo.setActualCarrierBusinessLicense(
                    StringUtils.isNotBlank(hyVehicle.getBusinessLicense()) ? hyVehicle.getBusinessLicense() :
                            hyVehicle.getRoadTransportNumber().substring(0 , 6) +"000000"
            );
            actualCarrierInfo.setActualCarrierId(hyVehicle.getOwnerCode());
        }

        shippingNoteDTO.setActualCarrierInfo(actualCarrierInfo);

        //保险信息
        baseReportService.getInsuranceInformation(shippingNoteDTO);
        shippingNoteDTO.setAppkey(appId);
        root.setShippingNote(shippingNoteDTO);

        XStream xstream = new XStream(new DomDriver( "utf-8"));
        xstream.aliasSystemAttribute(null, "class");
        xstream.processAnnotations(LiaoningReqModel.class);

        return xstream.toXML(exchangeModel);
    }


    private String buildFinancialXMLData(List<HyShippingNoteBill> shippingNoteBills, HyShippingNote hyShippingNote, String appId, String passwd) {

        HyDriverBank hyDriverBank = this.hydriverBankService.getDriverSelfBank(hyShippingNote.getDriverId());
        if (null == hyDriverBank) {
            throw new JeecgBootException("未找到司机绑定的银行卡信息");
        }

//        HyDriverBill hyDriverBill = this.hyDriverBillService.getBillByShippingId(hyShippingNote.getId());
//        if (null == hyDriverBill) {
//            throw new JeecgBootException("未找到银行流水单");
//        }

        HyVehicle hyVehicle = this.vehicleService.getById(hyShippingNote.getVehicleId());
        if (hyVehicle.getOwner().contains("公司") && StrUtil.isEmpty(hyVehicle.getOwnerCode())) {
            throw new JeecgBootException("车辆所有人社会信用代码错误");
        }

        //头部信息
        LiaoningReqModel exchangeModel = new LiaoningReqModel();
        LiaoningReqModel.Root root = new LiaoningReqModel.Root();
        exchangeModel.setRoot(root);
        LiaoningReqModel.Header header = buildHeaderData(appId,
                ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_ZJ.getMsg(),
                ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_ZJ.getCode(),
                passwd);
        root.setHeader(header);

        FinancialDTO financialDTO = new FinancialDTO();
        HyShippingNoteBill  shippingNoteBillDb =  shippingNoteBills.get(0);
        financialDTO.setDocumentNumber(shippingNoteBillDb.getBillNum());
        financialDTO.setSendToProDateTime(
                DateUtils.dateToStringDateTime(new Date())
        );
        if (!hyVehicle.getOwner().contains("公司")) {
            financialDTO.setCarrier(shippingNoteBillDb.getCarrier());
            financialDTO.setActualCarrierId(shippingNoteBillDb.getActualCarrierId());
        } else {
            financialDTO.setCarrier(hyVehicle.getOwner());
            financialDTO.setActualCarrierId(hyVehicle.getOwnerCode());
        }

        financialDTO.setVehicleNumber(shippingNoteBillDb.getVehicleNumber());
        financialDTO.setVehiclePlateColorCode(shippingNoteBillDb.getVehicleColorCode());

        //运单列表
        List <ShippingNoteListDTO> shippingNoteListDTOS = new ArrayList<>();
        ShippingNoteListDTO shippingNoteListDTO = new ShippingNoteListDTO();
        String shippingNoteNumber = shippingNoteBillDb.getShippingNoteNumber().replaceAll("-","");
        if(shippingNoteNumber.length() > 20 ){
            shippingNoteNumber =  shippingNoteNumber.substring(0, 20);
        }
        shippingNoteListDTO.setShippingNoteNumber(shippingNoteNumber);
        shippingNoteListDTO.setSerialNumber("0000");

        BigDecimal costPayShipping = hyShippingNote.getDriverFee() ;

        shippingNoteListDTO.setTotalMonetaryAmount(
                costPayShipping.setScale(3, BigDecimal.ROUND_DOWN).toString()
        );

        shippingNoteListDTOS.add(shippingNoteListDTO);
        financialDTO.setShippingNoteList(shippingNoteListDTOS);
        //财务列表
        List<FinanciallistDTO>  financiallistDTOS = new ArrayList <>();

        for(HyShippingNoteBill shippingNoteBill: shippingNoteBills){

            FinanciallistDTO financiallistDTO = new FinanciallistDTO();
            financiallistDTO.setPaymentMeansCode(
                    PaymentMeansCodeEnum.PAYMENT_MEANS_TYPE_YHZZ.code
            );
//            financiallistDTO.setReceiptAccount(
//                    "1".equals(shippingNoteBill.getBillImportFlag()) ?
//                            shippingNoteBill.getCraccno() :
//                            shippingNoteBill.getCraccno()+shippingNoteBill.getCrlogaccno()
//            );
            financiallistDTO.setReceiptAccount(hyDriverBank.getBankNum());
            financiallistDTO.setBankCode(shippingNoteBill.getBankCode());
            financiallistDTO.setRecipient(shippingNoteBill.getCarrier());
            financiallistDTO.setSequenceCode(shippingNoteBill.getBillNum());
            //financiallistDTO.setBankCode("SZDB");
            //financiallistDTO.setSequenceCode(shippingNoteBill.getBillNum());
            financiallistDTO.setMonetaryAmount(
                    shippingNoteBill.getAmt().setScale(3, BigDecimal.ROUND_DOWN).toString()
            );
            financiallistDTO.setDateTime(
                    DateUtils.dateToStringDateTime(shippingNoteBill.getPayDt())
            );

            financiallistDTOS.add(financiallistDTO);
        }

        financialDTO.setFinanciallist(financiallistDTOS);
        financialDTO.setAppkey(appId);
        root.setFinancial(financialDTO);
        XStream xstream = new XStream(new DomDriver( "utf-8"));
        xstream.aliasSystemAttribute(null, "class");
        xstream.processAnnotations(LiaoningReqModel.class);

        return xstream.toXML(exchangeModel);
    }


    private String buildEnterpriseXMLData(String actionType, String appId, String passwd) {

        //头部信息
        LiaoningReqModel exchangeModel = new LiaoningReqModel();
        LiaoningReqModel.Root root = new LiaoningReqModel.Root();
        exchangeModel.setRoot(root);
        LiaoningReqModel.Header header = buildHeaderData(appId,
                ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_QY.getMsg(),
                ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_QY.getCode(),
                passwd);
        root.setHeader(header);

        HyEnterprise hyEnterprise = enterpriseService.queryTopData();
        EnterpriseDTO enterpriseDTO = new EnterpriseDTO();
        //操作类型  1:新增操作 2：更新操作
        enterpriseDTO.setActionType(actionType);
        enterpriseDTO.setEntName(hyEnterprise.getEntName());
        enterpriseDTO.setUnifiedSocialCreditIdentifier(hyEnterprise.getUnifiedSocialCreditIdentifier());
        enterpriseDTO.setEntAddress(hyEnterprise.getEntAddress());
        enterpriseDTO.setAreaCode(hyEnterprise.getAreaCode());
        enterpriseDTO.setRegisterMoney(hyEnterprise.getRegisterMoney());
        enterpriseDTO.setRegisterDate(
                DateUtils.dateToStringNoBar(hyEnterprise.getRegisterDate())
        );
        enterpriseDTO.setRunScope(hyEnterprise.getRunScope());
        enterpriseDTO.setPermitNumber(hyEnterprise.getPermitNumber());
        enterpriseDTO.setFaxNo(hyEnterprise.getFaxNo());
        enterpriseDTO.setLegalerName(hyEnterprise.getLegalerName());
        enterpriseDTO.setLegalerTel(hyEnterprise.getLegalerTel());
        enterpriseDTO.setContactsName(hyEnterprise.getContactsName());
        enterpriseDTO.setContactsTel(hyEnterprise.getContactsTel());
        //监测状态  监测状态：0：未开启；1：联调测试开启；2：正式监测开启
        enterpriseDTO.setMonitorsState(hyEnterprise.getMonitorsState());
        enterpriseDTO.setMonitorTime(
                DateUtils.dateToStringDateTime(hyEnterprise.getMonitorTime())
        );
        enterpriseDTO.setEnterpriseCreateTime(
                DateUtils.dateToStringNoBar(hyEnterprise.getEnterpriseCreateTime())
        );
        enterpriseDTO.setIpcNum(hyEnterprise.getIpcnum());
        enterpriseDTO.setPsnrnum(hyEnterprise.getPsnrnum());

        List<AppsDTO> appsDTOS = new ArrayList<>();
        AppsDTO apps1 = new AppsDTO();
//        apps1.setAppId("uni.UNID36D735");
//        apps1.setAppSecurity("0b8e2f58d305808dbb968a911854ea8f9c49e4c2f5e55527027637c76e6b834bfac8558e839f874324a92bef29ad5c01");
//        apps1.setAppType("1");
//        apps1.setAppName("诚川优货司机端");
        apps1.setAppId("uni.UNIED3D98A");
        apps1.setAppSecurity("b11bc650cd548bba75bfa2578831847d0c253b095803b6bb1c100a0cd5077db1e52d3eac43e3d0ee6c72b5fc5dfc7a22");
        apps1.setAppType("1");
        apps1.setAppName("中民智运司机端");
        appsDTOS.add(apps1);

//        AppsDTO apps2 = new AppsDTO();
//        apps2.setAppId("uni.UNIEEA6C54");
//        apps2.setAppSecurity("0b8e2f58d305808dbb968a911854ea8f9c49e4c2f5e55527027637c76e6b834bfac8558e839f874324a92bef29ad5c01");
//        apps2.setAppType("1");
//        apps2.setAppName("诚川优货司机端");
//        appsDTOS.add(apps2);

        enterpriseDTO.setApps(appsDTOS);
        enterpriseDTO.setAppkey(appId);

        root.setEnterprise(enterpriseDTO);

        XStream xstream = new XStream(new DomDriver( "utf-8"));
        xstream.aliasSystemAttribute(null, "class");
        xstream.processAnnotations(LiaoningReqModel.class);

        return xstream.toXML(exchangeModel);
    }

        //头部报文
    private LiaoningReqModel.Header buildHeaderData(String appId, String docTypeName, String ipcTypeName, String passwd) {
        LiaoningReqModel.Header header = new LiaoningReqModel.Header();
        header.setMessageReferenceNumber(UUID.randomUUID().toString().replace("-", ""));
        header.setDocumentName(docTypeName);
        header.setDocumentVersionNumber("2.0");
        //辽宁区域210000
        header.setSenderCode("210000");
        header.setEnterpriseSenderCode("21" + appId);
        header.setMessageSendingDateTime(
                DateUtils.dateToStringDateTime(new Date())
        );
        header.setIpcType(ipcTypeName);
        header.setPassw(passwd);
        return header;
    }

    private LiaoningRspModel buildResponseData(String XMLData, String firstNodeName) {
        XStream xstream = new XStream(new DomDriver( "utf-8"));
        xstream.alias(firstNodeName, LiaoningRspModel.class);
        xstream.ignoreUnknownElements();
        xstream.allowTypesByRegExp(new String[] {".*"});
        return (LiaoningRspModel)xstream.fromXML(XMLData);
    }

    private HyArea getAreaNames(String areaCode) {
        LambdaQueryWrapper<HyArea> queryWrapperArea = new LambdaQueryWrapper <>();
        queryWrapperArea.eq(HyArea::getAreaCode, areaCode);
        return hyAreaService.getOne(queryWrapperArea);
    }

}
